package com.hk.webapp.controller.admin;

import com.hk.webapp.annotations.AllowAnonymous;
import com.hk.webapp.annotations.SkipPermission;
import com.hk.webapp.error.BusinessErrorEnum;
import com.hk.webapp.res_config.FileUploadConfig;
import com.hk.webapp.res_config.OssConfig;
import com.hk.webapp.utils.FileUploadUtils;
import com.hk.webapp.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@SkipPermission
@RestController
public class UploaderController extends AdminBaseController {

    @Resource
    private FileUploadConfig fileUploadConfig;
    @Resource
    private OssConfig ossConfig;

    @AllowAnonymous
    @PostMapping(value = "/Uploader/Index")
    public ResultVo uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return ResultVo.createByErrorEnum(BusinessErrorEnum.FILE_UPLOADER_NOT_NULL);
        }
        String fileUriPath = FileUploadUtils.uploadFileByLocal(fileUploadConfig, file);
        return ResultVo.createBySuccessData(fileUriPath);
    }

}
